home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_016 / source.files / bmprintc.c next >
C/C++ Source or Header  |  1992-05-06  |  4KB  |  148 lines

  1. /*--------------------------------------------------------------*/
  2. /*                                */
  3. /*            bmprintc.c                */
  4. /*                                */
  5. /* print out a C-language representation of data for bitmap    */
  6. /*                                */ 
  7. /* By Jerry Morrison and Steve Shaw, Electronic Arts.        */
  8. /* This software is in the public domain.            */
  9. /*                                */
  10. /* This version for the Commodore-Amiga computer.        */
  11. /*                                */
  12. /*--------------------------------------------------------------*/
  13.  
  14. #include <iff/intuall.h>
  15. #undef NULL
  16. #include <lattice/stdio.h>
  17.  
  18. #define NO 0
  19. #define YES 1
  20.  
  21. static BOOL doCRLF;
  22.  
  23. PrCRLF(fp) FILE *fp; {
  24.     if (doCRLF) fprintf(fp,"%c%c",0xD,0xA); else fprintf(fp,"\n");
  25.     }
  26.     
  27. PrintBob(bm, fp, name) 
  28.     struct BitMap *bm; 
  29.     FILE *fp;
  30.     UBYTE *name; 
  31.     {
  32.     UWORD *wp;
  33.  
  34.     int p,j,nb;
  35.     int nwords = (bm->BytesPerRow/2)*bm->Rows;
  36.     
  37.     fprintf(fp,"/*----- bitmap : w = %ld, h = %ld ------ */",
  38.        bm->BytesPerRow*8, bm->Rows);
  39.  
  40.     PrCRLF(fp);
  41.     
  42.     for (p=0; p<bm->Depth; ++p) {
  43.     wp = (UWORD *)bm->Planes[p];
  44.     fprintf(fp, "/*------ plane # %ld: --------*/",p);
  45.     PrCRLF(fp);
  46.     fprintf(fp, "UWORD %s%c[%ld] = { ", name, (p?('0'+p):' '), nwords);
  47.     PrCRLF(fp);
  48.     for (j = 0 ;  ; j++) {
  49.         for (nb = 0; ; ) {
  50.             fprintf(fp,"  0x%lx", *wp++);
  51.         nb += 2;
  52.         if (nb == bm->BytesPerRow) { 
  53.             if (j == bm->Rows-1)  goto endplane;
  54.             else { fprintf(fp,", "); PrCRLF(fp);  break; }
  55.             }
  56.         else fprintf(fp,", ");
  57.         }
  58.         }
  59.     endplane: fprintf(fp," };");
  60.     PrCRLF(fp); PrCRLF(fp);
  61.     }
  62.     }
  63.  
  64. PSprite(bm,fp,name,p,dohead) 
  65.     struct BitMap *bm;
  66.     FILE *fp;
  67.     UBYTE *name;
  68.     int p;
  69.     BOOL dohead;
  70.     {
  71.     UWORD *wp0,*wp1;
  72.     int j,nwords;
  73.     int wpl = bm->BytesPerRow/2;
  74.     nwords =  2*bm->Rows + (dohead?4:0);
  75.     wp0 = (UWORD *)bm->Planes[p];
  76.     wp1 = (UWORD *)bm->Planes[p+1];
  77.     fprintf(fp,"UWORD %s[%ld] = {", name, nwords);
  78.     PrCRLF(fp);
  79.     if (dohead){
  80.     fprintf(fp,"  0x0000, 0x0000, /* VStart, VStop */");
  81.     PrCRLF(fp);
  82.     }
  83.     for (j=0 ; j<bm->Rows; j++) {
  84.     fprintf(fp,"  0x%lx, 0x%lx", *wp0, *wp1);
  85.     if (dohead || (j!=bm->Rows-1)) {
  86.         fprintf(fp, ",");
  87.         PrCRLF(fp);
  88.         }
  89.     wp0 += wpl;
  90.     wp1 += wpl;
  91.     }
  92.     if (dohead) fprintf(fp,"  0x0000, 0x0000 }; /* End of Sprite */");
  93.     else fprintf(fp," };");    
  94.     PrCRLF(fp); PrCRLF(fp);
  95.     }
  96.  
  97. static UBYTE one[] = "1";
  98.  
  99. PrintSprite(bm, fp, name, attach, dohdr)
  100.     struct BitMap *bm; FILE *fp;
  101.     UBYTE *name;
  102.     BOOL attach, dohdr;
  103.     {
  104.     fprintf(fp,"/*----- Sprite format: h = %ld ------ */", bm->Rows);
  105.     PrCRLF(fp);
  106.     if (bm->Depth>1) {
  107.     fprintf(fp, "/*--Sprite containing lower order two planes:   */");
  108.         PrCRLF(fp);
  109.     PSprite(bm,fp,name,0,dohdr);
  110.     }
  111.     if (attach && (bm->Depth > 3) ) {
  112.     strcat(name,one);
  113.     fprintf(fp, "/*--Sprite containing higher order two planes:   */");
  114.         PrCRLF(fp);
  115.     PSprite(bm,fp,name,2,dohdr);
  116.     } 
  117.     }
  118.  
  119. #define BOB 0
  120. #define SPRITE 1
  121.     
  122. BMPrintCRep(bm, fp, name, fmt) 
  123.     struct BitMap *bm;     /* Contains the image data */
  124.     FILE *fp;        /* file we will write to */
  125.     UBYTE *name;    /* name associated with the bitmap */    
  126.     UBYTE *fmt;     /* string of characters describing output fmt*/
  127.     {
  128.     BOOL attach, doHdr;
  129.     char c;
  130.     SHORT type;
  131.     doCRLF = NO;
  132.     doHdr = YES;
  133.     type = BOB;
  134.     attach = NO;
  135.     while ( (c=*fmt++) != 0 ) 
  136.     switch (c) {
  137.         case 'b': type = BOB; break;
  138.         case 's': type = SPRITE; attach = NO; break;
  139.         case 'a': type = SPRITE; attach = YES; break;
  140.         case 'n': doHdr = NO; break;
  141.         case 'c': doCRLF = YES; break;
  142.         }
  143.     switch(type) {
  144.     case BOB: PrintBob(bm,fp,name); break;
  145.     case SPRITE:  PrintSprite(bm,fp,name,attach,doHdr); break;
  146.     }
  147.     }
  148.